package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.CommissionService;
import com.yixun.qfbao.apidto.GetCommissionModelReqDto;
import com.yixun.qfbao.apidto.GetCommissionModelResDto;
import com.yixun.qfbao.apidto.GetCommissionRuleExportReqDto;
import com.yixun.qfbao.apidto.GetCommissionRuleExportResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.GetCommissionModelReqVo;
import com.yixun.qfbao.vo.GetCommissionRuleExportReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Date 2017/12/12
 * @Author sangtao
 * @Computer Administrator
 */
@Service("getCommissionRuleExportHander")
public class GetCommissionRuleExportHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetCommissionRuleExportHander.class);
    @Autowired
    private CommissionService commissionService;
    @Autowired
    private LoginUtils loginUtils;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        GetCommissionRuleExportReqVo req = (GetCommissionRuleExportReqVo)reqDto;
        GetCommissionRuleExportReqDto reqDto1 = req.getParams();
        PartnerInfo loginUser = loginUtils.getUser(reqDto1.getUserId());
        reqDto1.setCompanyId(loginUser.getHigherid());
        BaseResponseDTO<GetCommissionRuleExportResDto> res = new BaseResponseDTO<GetCommissionRuleExportResDto>();
        GetCommissionRuleExportResDto resDto = new GetCommissionRuleExportResDto();
        try {
            resDto = commissionService.getCommissionRuleExport(reqDto1);
        }catch(TServerException e){
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(e.getErrorMsg());
        } catch (Exception e) {
            logger.error("GetCommissionRuleExportHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("系统异常");
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        return res;
    }
}
